package com.czy.service.impl;

import com.czy.entity.MyUserDetails;
import com.czy.service.MyUserDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author czy
 * @date 2022-4-4 23:25
 */
@Service
@Slf4j
public class MyUserDetailServiceImpl implements MyUserDetailService {
    @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("{}请求登录",username);
        // 查询用户信息
        MyUserDetails userDetails = new MyUserDetails();
        userDetails.setUsername("czy");
        userDetails.setPassword(passwordEncoder.encode("123456"));
        // 查询用户角色信息 存入userDetails中

        return userDetails;
    }
}
